//
//  AlertView.m
//  Demo
//
//  Created by 振东 何 on 12-5-10.
//  Copyright (c) 2012年 开趣. All rights reserved.
//

#import "PromptView.h"
#import "QuartzCore/QuartzCore.h"

@interface PromptView ()
@property (retain, nonatomic) UILabel *promptLbl;

- (void)hidePromptView;

@end


@implementation PromptView
@synthesize promptLbl;

//- (void)dealloc
//{
//    [promptLbl release];
//    [super dealloc];
//}

+ (PromptView *)sharedPromptView
{
    static PromptView *promptView = nil;
    
    @synchronized(self)
    {
        if (!promptView)
        {
            promptView = [[PromptView alloc] init];
        }
    }
    
    return promptView;
}

- (id)init
{
    self = [super init];
    if (self)
    {
        promptLbl                    = [[UILabel alloc] init];
        promptLbl.font               = [UIFont systemFontOfSize:25];
        promptLbl.alpha              = 0.0f;
        promptLbl.textColor          = [UIColor orangeColor];
        promptLbl.textAlignment      = UITextAlignmentCenter;
        promptLbl.backgroundColor    = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
        promptLbl.layer.cornerRadius = 12;
    }
    return self;
}

- (void)showPrompt:(NSString *)prompt withFrame:(CGRect)frame atView:(UIView *)view
{
    promptLbl.text  = prompt;
    promptLbl.frame = frame;
    [view addSubview:promptLbl];
    
    [UIView beginAnimations:nil context:nil];
    promptLbl.alpha = 1.0f;
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:2.0f];
    [UIView commitAnimations];
    
    [self performSelector:@selector(hidePromptView) withObject:nil afterDelay:2.5];
}


- (void)hidePromptView
{
    [UIView beginAnimations:nil context:nil];
    promptLbl.alpha = 0.0;
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:2.0f];
    [UIView commitAnimations];
}


@end
